import java.util.Map;

import com.an.jackjson.CacheKeyUtil;
import com.an.json.PhoneNumber;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;

import redis.clients.jedis.Jedis;

/**
 * @author Administrator
 *
 */
public class PhoneSetToRedis {

	/**
	 * @param args
	 */
	@SuppressWarnings("unchecked")
	public static void main(String[] args) {

		CacheKeyUtil cacheKeyUtil = new CacheKeyUtil();
		ObjectMapper objectMapper = new ObjectMapper();
		// json字符串中可以有vo中没有的字段
		objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
		PhoneNumber phoneNumber = new PhoneNumber();

		// 号码
		String number = "18668172228";
		// 客户ID
		String customerId = "86af8f8215b54dac8641e72dd226ab5f";
		// 区号
		String areaCode = "0571";
		// 号码类型
		String numberType = PhoneNumber.PHONE_NUMBER_TYPE_Y;
		// 服务类型
		String serviceType = PhoneNumber.SERVICE_CODE_AXYB;
		// 短信中心
		String smsCenter = "";
		// imsi
		String imis = "460018176615545";
		phoneNumber.setAreaCode(areaCode);
		phoneNumber.setPhoneNumber(number);
		phoneNumber.setPhoneNumberType(numberType);
		phoneNumber.setServiceCode(serviceType);
		phoneNumber.setProvinceCode("");
		phoneNumber.setCustomerId(customerId);
		phoneNumber.setImsi(imis);
		phoneNumber.setSmsCenterNumber(smsCenter);

		Map<String, String> map;
		try {
			map = objectMapper.readValue(objectMapper.writeValueAsString(phoneNumber), Map.class);
			// 绑定X号码
			map.remove("binding");
			map.remove("axbBindingPhoneNumberMap");
			// X号码绑定A号码

			Jedis jedis = new Jedis("127.0.0.1");
//			jedis.auth("AS@redis");
			jedis.hmset(cacheKeyUtil.getPhoneNumberKey(number), map);
			jedis.hset(cacheKeyUtil.getCustomerPhoneNumberKey(customerId), number,
					numberType);
		} catch (Exception e) {
		}

	}

}
